//修复iphone通知栏
// function fixIos7Bar (el){
//     if(!el&&el.nodeType==1){
//         console.warn('$api.fixIos7Bar Function need el param, el param must be DOM Element');
//         return;
//     }
//     var strDM = api.systemType;
//     if (strDM == 'ios') {
//         var strSV = api.systemVersion;
//         var numSV = parseInt(strSV.slice(0,strSV.indexOf('.')),10);
//         var fullScreen = api.fullScreen;
//         var iOS7StatusBarAppearance = api.iOS7StatusBarAppearance;
//         if (numSV >= 7 && !fullScreen && iOS7StatusBarAppearance) {
//             el.style.paddingTop = '20px';
//         }
//     }
// };
// //修复iphone通知栏
// function fixStatusBar (el){
//     if(!el&&el.nodeType==1){
//         console.warn('$api.fixStatusBar Function need el param, el param must be DOM Element');
//         return;
//     }
//     var sysType = api.systemType;
//     if(sysType == 'ios'){
//         fixIos7Bar(el);
//     }else if(sysType == 'android'){
//         var ver = api.systemVersion;
//         ver = parseFloat(ver);
//         if(ver >= 4.4){
//             // el.style.paddingTop = '25px';
//         }
//     }
// };



//**自定义post函数
//**函数参数：values（json），userAgent名称，url地址,fun（回调函数）
//**常量设置
//**
const userAgentDefalut = '51jili';
const appid = '06wygzvDdr062rNwIXTC';
const appkey = 'vxCdATZ76WeqjhF3ZNHu';
const appver = '2.5.0';
const apptype = 'ios';
function apiPost(params){
  // url,values,fun,userAgent
  if(Object.getOwnPropertyNames(params).length<4){
    params.userAgent = userAgentDefalut;
  };
  var signature  = api.require('signature');
  var valuesObj = params.values,
      arr=[],
      hash;
  valuesObj.time = Date.parse(new Date());
  valuesObj.appver = appver;
  valuesObj.apptype = apptype;
  for(var item in valuesObj){
      var temp = item+':'+valuesObj[item];
      arr.push(temp);
  }
  arr.sort();
  var str = '';
  for(var i of arr){
    var index = i.indexOf(':');
    var temp = i.slice(0,index)+'='+i.slice(index+1);
    str += temp+'&';
  }
  str += 'appid='+appid+'&appkey='+appkey;
  signature.md5({
    data:str
  },function(ret,err){
    if(ret.status){
      hash = ret.value;
      valuesObj.sign = hash;
      api.ajax({
        url: params.url,
        method: 'post',
        headers:{
            "User-Agent":params.userAgent,
            "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"
        },
        data:{
            values:valuesObj
        },
      }, function(ret, err) {
        params.fun(ret,err);
      })
    }else{
      //弹出转md5的错误
      alert(JSON.stringify(err))
    }
  })
}

//***
//**等待中showProgress
//**
function showWaitingProgress(){
  api.showProgress({
      text:'使劲加载中..',
      title: '客官请稍等..',
      modal: true,
      animationType:'fade'
  });
}

//***
//**网络异常showProgress
//**
function showNetErrorProgress(){
  api.showProgress({
      title: '请检查网络设置',
      text:'网络异常',
      modal: true,
      animationType:'fade'
  });
  setTimeout(function(){
    api.hideProgress();
  },1500)
}




/*******************************************************************/
//验证信息弹出框显示关闭
  $.fn.showErrorMsg = function(){
      $(this).removeClass('fadeOutDown animated').addClass('fadeInUp animated')
      .parent().css({
          'display':'block',
          'zIndex':30
      })
      setTimeout(function(){
          this.removeClass('fadeInUp animated').addClass('fadeOutDown animated');
          setTimeout(function(){
              this.parent().css({
                  'zIndex':-1,
                  'display':'none'
              }).empty();
          }.bind(this),500);
      }.bind(this),1500);
      return this
  };
  //自定义消息内容
  $.extend ({
      showCustomErrorMsg :function(content){
          if($('#errorBox').children().length==0){
              $('<div>').appendTo('#errorBox').addClass('showerror').html(content).showErrorMsg();
          }
      }
  })
  //模态框显示
  $.fn.showModal = function(mIn,mOut,addModalBg){
      //默认添加一个背景
      var modalin = !mIn?  'fadeInDown':mIn;
      var modalout = !mOut? 'fadeOutUp' :mOut;
      var modalBg = addModalBg==false? addModalBg : true;//是否添加背景
      var cName = this[0].className;
      var wordsPUM = cName.slice(cName.indexOf('popUpModal'));
      this.css({
          'display':'block',
          'zIndex':29
      });
      $('body').css('overflow','hidden');
      if(modalBg){
          $('<div>').appendTo('body').addClass('modal animated fadeIn').click(function(){
              $('.popUpModal').closeModal(mIn,mOut);
          }.bind(this));
      }
      //移除除第一个单词以外其他的单词
      this.removeClass(wordsPUM).addClass(' popUpModal animated '+modalin);
  };
  //模态框关闭
  $.fn.closeModal=function(mIn,mOut,bgClose){
      //默认全部背景关闭
      var modalin = !mIn?  'fadeInDown':mIn;
      var modalout = !mOut? 'fadeOutUp' :mOut;
      var mBgClose = bgClose==false? bgClose :true;//是否关闭背景
      var cName = this[0].className;
      var wordsPUM = cName.slice(cName.indexOf('popUpModal'));
      //移除除第一个单词以外其他的单词
      this.removeClass(wordsPUM).addClass(' popUpModal animated '+modalout);
      if(mBgClose){
          $('div.modal').unbind().removeClass('fadeIn').addClass('fadeOut');
      }
      $('body').css('overflow','auto');
      setTimeout(function(){
          this.css({
              'zIndex':-1,
              'display':'none'
          });
          if(mBgClose){
              $('div.modal').remove();
          }
      }.bind(this),500);
  };
